SubscriptionRefType

SubscriptionRef

SubscriptionRef<'a> is a reference whose changes can be streamed. changes starts with the value current when the stream starts, then delivers every later update, with no gap and no duplicate between the two, buffered by a QueueStrategy chosen per stream.

Use it for state that consumers join at different times, such as a display opened after a feed started. Update it with set, update, or modify; each update reaches every running stream before the next starts.

Read the SubscriptionRef guide.

Specification

Kind
Type
Members
6
Examples
0
makeSignature
SubscriptionRef.make value
getSignature
SubscriptionRef.get reference
setSignature
SubscriptionRef.set value reference
updateSignature
SubscriptionRef.update mapping reference
modifySignature
SubscriptionRef.modify mapping reference

Summary

NameSignatureSynopsis
Operations
makeSubscriptionRef.make valueCreates a reference holding value.
getSubscriptionRef.get referenceReads the current value.
setSubscriptionRef.set value referenceReplaces the value and delivers it to every changes stream.
updateSubscriptionRef.update mapping referenceApplies a pure function to the value and delivers the result to every changes stream.
modifySubscriptionRef.modify mapping referenceComputes a result and a new value together, stores the new value, and returns the result.
changesSubscriptionRef.changes strategy referenceStreams the current value followed by every later update, buffered for this stream by strategy.

Operations

kind:member

make

SubscriptionRef.make value
Member
Creates a reference holding value.

Parameters

NameTypeDescription
value'a

Returns

Flow<'env, 'error, SubscriptionRef<'a>>

Verification Examples

open Axial.State

let temperature : Flow<unit, Never, SubscriptionRef<float>> = SubscriptionRef.make 20.0
kind:member

get

SubscriptionRef.get reference
Member
Reads the current value.

Parameters

NameTypeDescription
referenceSubscriptionRef<'a>

Returns

Flow<'env, 'error, 'a>
kind:member

set

SubscriptionRef.set value reference
Member
Replaces the value and delivers it to every changes stream.

Parameters

NameTypeDescription
value'a
referenceSubscriptionRef<'a>

Returns

Flow<'env, 'error, unit>

Verification Examples

temperature |> SubscriptionRef.set 21.5
kind:member

update

SubscriptionRef.update mapping reference
Member
Applies a pure function to the value and delivers the result to every changes stream.

Parameters

NameTypeDescription
mapping'a -> 'a
referenceSubscriptionRef<'a>

Returns

Flow<'env, 'error, unit>
kind:member

modify

SubscriptionRef.modify mapping reference
Member
Computes a result and a new value together, stores the new value, and returns the result.

Parameters

NameTypeDescription
mapping'a -> 'result * 'a
referenceSubscriptionRef<'a>

Returns

Flow<'env, 'error, 'result>
kind:member

changes

SubscriptionRef.changes strategy reference
Member
Streams the current value followed by every later update, buffered for this stream by strategy.

Parameters

NameTypeDescription
strategyQueueStrategy
referenceSubscriptionRef<'a>

Returns

FlowStream<'env, 'error, 'a>

Verification Examples

temperature
|> SubscriptionRef.changes (QueueStrategy.Sliding 1)
|> FlowStream.runForEach (printfn "%.1f")